#include<bits/stdc++.h>
#define int long long
using namespace std;
namespace IO
{
	template<typename T>
	void read(T &_x){_x=0;int _f=1;char ch=getchar();while(!isdigit(ch)) _f=(ch=='-'?-1:_f),ch=getchar();while(isdigit(ch)) _x=_x*10+(ch^48),ch=getchar();_x*=_f;}
	template<typename T,typename... Args>
	void read(T &_x,Args&...others){Read(_x);Read(others...);}
	const int BUF=20000000;char buf[BUF],to,stk[32];int plen;
	#define pc(x) buf[plen++]=x
	#define flush(); fwrite(buf,1,plen,stdout),plen=0;
	template<typename T>inline void print(T x){if(!x){pc(48);return;}if(x<0) x=-x,pc('-');for(;x;x/=10) stk[++to]=48+x%10;while(to) pc(stk[to--]);}
}
using namespace IO;
const int N = 8e5+10,Z = 20;
int n,x,y,z,head[N],v[N],ans[N],sum,cnt,cnt1,siz[N];
struct w
{
	int to,nxt,z,id;
}a[N<<1];
inline void add(int x,int y,int z,int id)
{
	a[++cnt].nxt = head[x];
	a[cnt].id = id;
	a[cnt].to = y,a[cnt].z = z;
	head[x] = cnt;
}
void dfs(int x,int y,int z)
{
	v[x] = 1,cnt1++,siz[x] = 1;
	for(int i = head[x];i;i = a[i].nxt)
		if(a[i].to != y && a[i].z >= z) dfs(a[i].to,x,z),siz[x] += siz[a[i].to];
}
void dfs1(int x,int y,int z,int id)
{
	if(id != 0) ans[id] += (cnt1-siz[x])*(siz[x]); 
	for(int i = head[x];i;i = a[i].nxt)
		if(a[i].to != y && a[i].z >= z) 
			dfs1(a[i].to,x,z,a[i].id);
}
signed main()
{
	freopen("tatooine.in","r",stdin);
	freopen("tatooine.out","w",stdout);
	read(n);
	for(int i = 1;i < n;i++) read(x),read(y),read(z),add(x,y,z,i),add(y,x,z,i);
	for(int i = 1;i <= Z;i++)
	{
		for(int j = 1;j <= n;j++) v[j] = siz[j] = 0; 
		for(int j = 1;j <= n;j++) 
			if(!v[j]) 
			{
				cnt1 = 0,dfs(j,0,i);
				sum += cnt1*(cnt1-1)/2,dfs1(j,0,i,0);
			}
	}
	for(int i = 1;i < n;i++) print(sum-ans[i]),pc('\n');
	flush();
	return 0;
}
